package com.jia.train.global.context;

import com.jia.train.global.auth.BaseUserResponse;
import org.springframework.core.NamedInheritableThreadLocal;
import org.springframework.core.NamedThreadLocal;

public class AuthContextHolder {

    private static final ThreadLocal<BaseUserResponse> context = new NamedThreadLocal<>("context");

    private static final ThreadLocal<BaseUserResponse> inheritableContext = new NamedInheritableThreadLocal<>("inheritableContext");

    public static BaseUserResponse getContext() {
        return context.get();
    }

    public static Long getId() {
        return context.get().getId();
    }

    public static void clearContext() {
        context.remove();
    }

    public static void setContext(BaseUserResponse response) {
        AuthContextHolder.context.set(response);
    }

    public static BaseUserResponse getInheritableContext() {
        return inheritableContext.get();
    }

    public static void setInheritableContext(BaseUserResponse response) {
        inheritableContext.set(response);
    }


}
